import log4js from "log4js";
/**
 * !文档
 * https://blog.csdn.net/bird_tp/article/details/122882356
 */
log4js.configure({
  appenders: {
    // 终端输出
    console: { type: "console" },
    // 日志输出的方式
    file: {
      type: "file", // 类型
      filename: process.cwd() + "/logs/all.log", //名称
      //   日志内容格式
      layout: {
        type: "pattern",
        pattern: "[%p] %d{yyyy-MM-dd hh:mm:ss} %m",
      },
    },

    // 日志分割
    ddayfile: {
      type: "dateFile",
      //   filename: "all.log",
      filename: process.cwd() + "/logs/all.log", //名称
      pattern: "yyyyMMdd",
      layout: {
        type: "pattern",
        pattern: "[%p] %d{yyyy-MM-dd hh:mm:ss} %m",
      },
    },
    request: {
      type: "dateFile",
      //   filename: "all.log",
      filename: process.cwd() + "/logs/request.log", //名称
      pattern: "yyyyMMdd",
      layout: {
        type: "pattern",
        pattern: "[%p] %d{yyyy-MM-dd hh:mm:ss} %m",
      },
    },
    webSocket: {
      type: "dateFile",
      //   filename: "all.log",
      filename: process.cwd() + "/logs/webSocket.log", //名称
      pattern: "yyyyMMdd",
      layout: {
        type: "pattern",
        pattern: "[%p] %d{yyyy-MM-dd hh:mm:ss} %m",
      },
    },
  },
  //   日志配置
  categories: {
    default: {
      appenders: ["console", "ddayfile"],
      level: "all",
    },
    request: {
      appenders: ["console", "request"],
      level: "info",
    },
    webSocket: {
      appenders: ["console", "webSocket"],
      level: "info",
    },
  },
});

// all < trace < debug < info < warn < error < fatal < mark < off
// 全部   跟踪    调试     信息   警告    错误 致命的错误  标记  离开

export const CODE = {
  0: "系统",
  1: "业务",
  2: "微信",
  system: 0,
  business: 1,
  wechat: 2,
};

export const logger = log4js.getLogger();
export const requestLogger = log4js.getLogger("request");
export const webSocketLogger = log4js.getLogger("webSocket");
